/**
 * 常用工具函数
 */

// 防抖函数
export const debounce = (fn, delay = 300) => {
    let timer = null
    return function (...args) {
        if (timer) clearTimeout(timer)
        timer = setTimeout(() => {
            fn.apply(this, args)
        }, delay)
    }
}

// 节流函数
export const throttle = (fn, delay = 300) => {
    let lastTime = 0
    return function (...args) {
        const now = Date.now()
        if (now - lastTime > delay) {
            fn.apply(this, args)
            lastTime = now
        }
    }
}

// 深拷贝简单实现
export const deepClone = (obj) => {
    if (typeof obj !== 'object' || obj === null) return obj
    return JSON.parse(JSON.stringify(obj))
}